home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-07 | 15.5 KB | 556 lines | [TEXT/MPS ] |
- (*
- vidDrvrS1500(cmd,parameters) -- Driver for the Sony 1500 videodisc player. The cmd parameter specifies the
- function to be performed (p1 is the first parameter after cmd; p2 is the second, etc.):
-
- Command Function
- --------- --------
- chapter Return the chapter currently being displayed.
- control Execute a series of control functions. Each addition parameter is a keyword to be
- executed. If the keyword doesn't make sense here, pass it on to configureSPort.
- The following keywords are understood by the video driver:
- Keyword Function
- -------- --------
- init or reset Reset the player, configure the serial port (the baud rate is set to
- the highest available for the selected player).
- eject or reject Eject the disc from the player.
- audioOff Turn off both audio channels.
- audio1On Turn on audio channel 1.
- audio2On Turn on audio channel 2.
- stereoOn Turn on both audio channels.
- pictureOn/pictureOff Turn on/off the picture.
- framesOn/framesOff Turn on/off the display of frame numbers.
- frameMode Set player to frame number mode.
- chapterMode Set player to chapter number mode.
- timeMode Set player to time mode.
- defaultComm Set default communications settings for this player.
- extended Execute a function specific to the player. This player doesn't have any (yet).
- fps Set the frames per second for the next playVideo command to p1, which can be a number or
- one of "slowest", "slower", "slow", "normal", "fast", "faster", "fastest".
- frame Return the current frame number.
- name Return the long name of the player.
- play Start a sequence playing, from p1 to p2, which are frame numbers, chapter numbers, or times,
- depending upon the mode.
- scan Scan forward or backward, depending upong whether p1 is "forward" or "backward".
- search Search to frame, chapter, or time p1.
- sendCmd Send command p1 to the player and wait for an acknowlege.
- speeds Return the frames per second speeds allowed with this player.
- status Return the status of the play, which is a comma-separated list containing:
- Keyword Meaning
- -------- --------
- doorOpen or park or still or play State of player.
- CLV or CAV Type of disc.
- disc12inch or disc8inch Size of disc being played.
- side1 or side2 Side of disc being played.
- step Step p1 frames forward (or backward if it's negative), and do it p2 times.
- time Return the time of the frame currently being displayed, in 1/60ths of a second since the start
- of the disc.
- version Return the version of this player driver.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w vidDrvrS1500.p
- link -m ENTRYPOINT -o HyperCommands -rt XFCN=8032 -sn Main=vidDrvrS1500 ∂
- vidDrvrS1500.p.o "{MPW}"Libraries:interface.o "{MPW}"PLibraries:PasLib.o
-
- Copyright © 1988 Apple Computer, Inc.
-
- 2/88 - Initial coding by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S vidDrvrS1500 } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- type
-
- Str31 = String[31];
-
- procedure vidDrvrS1500(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- vidDrvrS1500(paramPtr);
- end;
-
- procedure vidDrvrS1500(paramPtr: XCmdPtr);
-
- var returnValue: str255;
- pCount: integer;
- p1, p2: str255;
- str: str255;
- i: integer;
- inChapterMode: boolean;
-
- {$I XCmdGlue.inc}
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(errMsg);
- exit(vidDrvrS1500);
- end;
-
- {$I VideoUtil.inc}
-
- procedure sendCmd(theCommand: str255);
- { Send a command to the player, waiting for the ack. If noReset is empty,
- then send a reset first. }
-
- var i: integer;
-
- begin
- for i := 1 to length(theCommand) do
- begin
- SendCardMessage(Concat('sendSPort "',Copy(theCommand,i,1),'"'));
- EvalAndDispose('RecvUpTo(numToChar(10),600,empty)');
- end;
- end;
-
- function frame: str255;
- { Return the current frame number. }
-
- var str: str255;
- endTick: longInt;
-
- begin
- { Get the current frame number... }
- SendCardMessage('sendSPort "`"');
- str := '';
- endTick := TickCount+120;
- repeat
- str := EvalStr(Concat('recvUpTo(empty,0,"',str,'")'));
- if length(str) = 1 then
- if str[1] = chr(11) then
- begin
- frame := 'noDisc';
- exit(frame);
- end;
- until (length(str) >= 5) or (TickCount > endTick);
- if length(str) < 5 then frame := 'noAnswer'
- else frame := str;
- end;
-
- function chapter: str255;
- { Return the current chapter number. }
-
- var str: str255;
- endTick: longInt;
-
- begin
- { Get the current chapter number... }
- SendCardMessage('sendSPort "v"');
- str := '';
- endTick := TickCount+120;
- repeat
- str := EvalStr(Concat('recvUpTo(empty,0,"',str,'")'));
- if length(str) = 1 then
- if str[1] = chr(11) then
- begin
- chapter := 'noChapters';
- exit(chapter);
- end;
- until (length(str) >= 2) or (TickCount > endTick);
- if length(str) < 2 then chapter := 'noAnswer'
- else chapter := str;
- end;
-
- function time: str255;
- { Return the time of the current frame. }
-
- begin
- time := 'notImplemented';
- end;
-
- procedure search(var toFrame: str255; blankSearch: boolean);
- { Search to a particular frame, blanking on the way if blankSearch is true. }
-
- begin
- if blankSearch then sendCmd('&');
- sendCmd(Concat('C',toFrame,'@'));
- EvalAndDispose('recvUpTo(numToChar(1),600,empty)');
- if blankSearch then sendCmd('''');
- end;
-
- procedure stop;
- { Stop the player. }
-
- begin
- sendCmd('O');
- end;
-
- procedure control(var keywd: str255);
- { Handle a control command. }
-
- type
- audioModes = (off,oneOn,twoOn,stereo);
-
- var numberOfParms: integer;
- i: integer;
- parm: str255;
-
- procedure ejectPlayer;
- { Eject the disc. }
-
- begin
- { Send the appropriate eject command. }
- sendCmd('*');
- end;
-
- procedure audio(onOff: audioModes);
- { Set the audio mode. }
-
- begin
- { Send the appropriate audio channel command. }
- case onOff of
- off:
- begin
- sendCmd('G');
- sendCmd('I');
- end;
- oneOn:
- begin
- sendCmd('F');
- sendCmd('I');
- end;
- twoOn:
- begin
- sendCmd('G');
- sendCmd('H');
- end;
- stereo:
- begin
- sendCmd('F');
- sendCmd('H');
- end;
- end;
- end;
-
- procedure picture(onOff: boolean);
- { Turn on or off the picture. }
-
- begin
- { Send the appropriate picture command. }
- if onOff then sendCmd('''')
- else sendCmd('&');
- end;
-
- procedure frames(onOff: boolean);
- { Turn on or off the frame display. }
-
- begin
- { Send the appropriate frame display command. }
- if onOff then sendCmd('P')
- else sendCmd('Q');
- end;
-
- procedure defaultComm;
- { Set the default communications parameters. }
-
- begin
- { Set the port configuration. }
- SendCardMessage('configureSPort baud9600,echoOff,editOff,linefeedOff,stripOff');
- end;
-
- procedure setMode(theMode: str255);
- { Set the frame/chapter/time mode. }
-
- begin
- SetStrGlobal('videoMode',theMode);
- if StringEqual(theMode,'chapterMode') then sendCmd('Vi')
- else if StringEqual(theMode,'timeMode') then sendCmd('VU')
- else sendCmd('VU');
- end;
-
- procedure initPlayer;
- { Initialize the player. }
-
- begin
- { Empty out the globals. }
- SetStrGlobal('videoMode','');
- SetStrGlobal('blankNextVideo','');
- SetStrGlobal('videoSpeed','');
-
- { Send the reset command for this player. }
- sendCmd('V');
-
- { Force it to stop. }
- stop;
-
- { Reset the player to known defaults. }
- setMode('');
- audio(stereo);
- frames(false);
- picture(true);
- end;
-
- begin
- if StringEqual(keywd,'init') or StringEqual(keywd,'reset') then initPlayer
- else if StringEqual(keywd,'eject') or StringEqual(keywd,'reject') then ejectPlayer
- else if StringEqual(keywd,'audioOff') then audio(off)
- else if StringEqual(keywd,'audio1On') then audio(oneOn)
- else if StringEqual(keywd,'audio2On') then audio(twoOn)
- else if StringEqual(keywd,'stereoOn') then audio(stereo)
- else if StringEqual(keywd,'pictureOn') then picture(true)
- else if StringEqual(keywd,'pictureOff') then picture(false)
- else if StringEqual(keywd,'framesOn') then frames(true)
- else if StringEqual(keywd,'framesOff') then frames(false)
- else if StringEqual(keywd,'defaultComm') then defaultComm
- else if StringEqual(keywd,'frameMode') then setMode('')
- else if StringEqual(keywd,'chapterMode') then setMode('chapterMode')
- else if StringEqual(keywd,'timeMode') then setMode('timeMode')
- else SendCardMessage(Concat('configureSPort ',keywd));
- end;
-
- function extended(var keywd: str255): str255;
- { Execute an extended command or function. }
-
- begin
- { No extended command for this player. }
- end;
-
- procedure fps(var fpsKeywd: str255);
- { Set the frames per second. }
-
- var speed: str255;
-
- begin
- speed := '';
-
- { Default speed settings are fine, except: }
- if StringEqual(fpsKeywd,'fast') then speed := '90'
- else if StringEqual(fpsKeywd,'fastest') then speed := '90';
-
- { Set it. }
- if speed <> '' then SetStrGlobal('videoSpeed',speed);
- end;
-
- function name: str255;
- { Return the long name of the player. }
-
- begin
- name := 'Sony 1500';
- end;
-
- procedure play(var firstFrame,lastFrame,speed: str255; blankSearch, chapterMode: boolean);
- { Play a segment. }
-
- var lastFrameNum: longInt;
- startHere: boolean;
- playToLast: boolean;
- fpsNum: longInt;
- rev: boolean;
-
- begin
- { Figure out if we're playing to special (non-numeric markers). }
- startHere := StringEqual(firstFrame,'here');
- playToLast := StringEqual(lastFrame,'lastFrame');
- if playToLast then
- begin
- if chapterMode then
- begin
- lastFrame := '99';
- lastFrameNum := 99;
- end
- else
- begin
- lastFrame := '54000';
- lastFrameNum := 54000;
- end;
- end
- else lastFrameNum := StrToLong(lastFrame);
- fpsNum := StrToLong(speed);
-
- { Figure out whether we're playing forward or reverse. }
- rev := (not playToLast) and
- (((not startHere) and (lastFrameNum < StrToLong(firstFrame))) or (lastFrameNum = 0));
-
- { Go to the first frame. }
- if (not startHere) and ((not chapterMode) or playToLast or (lastFrameNum = 0)) then
- search(firstFrame,blankSearch);
- { Play it. }
- if playToLast and (fpsNum = 30) then sendCmd(':')
- else if (lastFrameNum = 0) and (fpsNum = 30) then sendCmd('J')
- else
- begin
- if (not playToLast) and (lastFrameNum <> 0) and ((fpsNum = 30) or (not chapterMode)) then
- begin
- sendCmd('D');
- if not playToLast then
- begin
- if chapterMode then sendCmd(Concat(LongToStr(lastFrameNum-1),'@01@'))
- else sendCmd(Concat(lastFrame,'@01@'));
- end
- else sendCmd('@01@');
- end;
- if fpsNum > 30 then
- begin
- if rev then sendCmd('K')
- else sendCmd(';');
- end
- else if fpsNum < 30 then
- begin
- if rev then sendCmd('M')
- else sendCmd('=');
- if fpsNum = 15 then sendCmd('2@')
- else if fpsNum = 10 then sendCmd('3@')
- else if fpsNum = 3 then sendCmd('10@')
- else sendCmd('30@');
- end;
- end;
- end;
-
- function scan(scanForward: boolean): str255;
- { Scan forward (if scanForward is true), or backward. }
-
- begin
- if scanForward then sendCmd('>')
- else sendCmd('N');
- scan := 'only once';
- end;
-
- procedure step(goForward: boolean);
- { Step one frame forward (if goForward is true) or backward. }
-
- begin
- if goForward then SendCmd('=O')
- else SendCmd('MO');
- end;
-
- function speeds: str255;
- { Return the valid speeds for this player. }
-
- begin
- speeds := '1,3,10,15,30,90';
- end;
-
- function status: str255;
- { Return the current status of the player. }
-
- var str3, str5: str255;
- endTick: longInt;
- charCount: integer;
- theResult: str255;
-
- begin
- { Clear out any pending input. }
- EvalAndDispose('recvUpTo(empty,0,empty)');
-
- { Get the current frame number... }
- SendCardMessage('sendSPort "g"');
- endTick := TickCount+120;
- repeat charCount := StrToLong(Evalstr('charsAvailable()'));
- until (charCount >= 5) or (TickCount > endTick);
- { If we got something... }
- if charCount >= 5 then
- begin
- { str3 := character three. }
- EvalAndDispose('recvChars(2)');
- str3 := EvalStr('recvChars(1)');
- if length(str3) = 0 then
- begin
- str3[0] := chr(1); str3[1] := chr(0);
- end;
- { str5 := character five. }
- EvalAndDispose('recvChars(1)');
- str5 := EvalStr('recvChars(1)');
- if length(str5) = 0 then
- begin
- str5[0] := chr(1); str5[1] := chr(0);
- end;
- { Figure out the current status. }
- if BitAnd(ord(str5[1]),127) = 0 then theResult := 'park,'
- else if BitAnd(ord(str5[1]),96) <> 0 then theResult := 'still,'
- else theResult := 'play,';
- if BitAnd(ord(str3[1]),32) <> 0 then theResult := Concat(theResult,'CLV,')
- else theResult := Concat(theResult,'CAV,');
- if BitAnd(ord(str3[1]),16) <> 0 then theResult := Concat(theResult,'disc12inch')
- else theResult := Concat(theResult,'disc8inch');
- status := theResult;
- end
- else status := 'noAnswer';
- end;
-
- function version: str255;
- { Return the version of the player driver. }
-
- begin
- version := 'S1500 1.2';
- end;
-
- begin
- pCount := paramPtr^.paramCount;
-
- if pCount <= 0 then Fail('parameter count is not > 0');
-
- if pCount > 1 then GetStrParm(2,p1)
- else p1 := '';
- if pCount > 2 then GetStrParm(3,p2)
- else p2 := '';
-
- GetStrParm(1,str);
-
- returnValue := '';
-
- if StringEqual(str,'chapter') then returnValue := chapter
- else if StringEqual(str,'control') then
- begin
- for i := 2 to pCount do
- begin
- GetStrParm(i,str);
- control(str);
- end;
- end
- else if StringEqual(str,'extended') then returnValue := extended(p1)
- else if StringEqual(str,'fps') then fps(p1)
- else if StringEqual(str,'frame') then returnValue := frame
- else if StringEqual(str,'name') then returnValue := name
- else if StringEqual(str,'play') then
- begin
- GetStrGlobal('videoMode',str);
- inChapterMode := StringEqual(str,'chapterMode');
- GetStrGlobal('blankNextVideo',str);
- if str = '' then
- begin
- GetStrGlobal('videoSpeed',str);
- play(p1,p2,str,false,inChapterMode);
- end
- else
- begin
- GetStrGlobal('videoSpeed',str);
- play(p1,p2,str,true,inChapterMode);
- end;
- end
- else if StringEqual(str,'scan') then
- begin
- if length(p1) < 1 then returnValue := scan(true)
- else returnValue := scan(not ((p1[1] = 'b') or (p1[1] = 'B')));
- end
- else if StringEqual(str,'search') then
- begin
- GetStrGlobal('blankNextVideo',str);
- search(p1,str <> '');
- end
- else if StringEqual(str,'sendCmd') then sendCmd(p1)
- else if StringEqual(str,'step') then step(p1 = '1')
- else if StringEqual(str,'speeds') then returnValue := speeds
- else if StringEqual(str,'status') then returnValue := status
- else if StringEqual(str,'stop') then stop
- else if StringEqual(str,'time') then returnValue := time
- else if StringEqual(str,'version') then returnValue := version;
-
- { Return the result (if any). }
- paramPtr^.returnValue := PasToZero(returnValue)
- end;
-
- end.
-